package tsscharts.impl;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import tsscharts.intf.IElement;
import tsscharts.intf.IStyle;

public class Element implements IElement {

	private final String tagName;

	private final IStyle style;

	private String innerHTML;

	public Element(String tagName) {
		this.tagName = tagName;
		this.style = new Style();
	}

	@Override
	public IStyle getStyle() {
		return style;
	}

	private static final Pattern pattern = Pattern.compile("<[^<>]+>|[^<>]+");

	@Override
	public void setInnerHTML(String innerHTML) {
		Matcher m = pattern.matcher(innerHTML);
		int start = 0, end = 0;
		while (start < innerHTML.length()) {
			m.find(start);
			end = m.end();
			System.out.println(innerHTML.substring(start, end));
			start = end;
		}
		this.innerHTML = innerHTML;
	}

	public void appendChild(IElement element) {
		// TODO Auto-generated method stub

	}

	@Override
	public IElement[] getElementsByTagName(String tagName) {
		// TODO Auto-generated method stub
		return null;
	}

}
